﻿#include "dtuadddialog.h"

DTUAddDialog::DTUAddDialog()
{
    setup_ui();
    connect(okButton, &QAbstractButton::clicked, this, &DTUAddDialog::slt_okButton);
    connect(cancelButton, &QAbstractButton::clicked, this, &QDialog::reject);
}

DTUAddDialog::~DTUAddDialog()
{

}

void DTUAddDialog::slt_okButton()
{
    if(name_ed->text().size() == 0 || pos_ed->text().size() == 0)
        QMessageBox::warning(NULL,  QStringLiteral("字符串不合法"),
                              QStringLiteral("不含空格和特殊符号,./:'等，不能为空"));
    else
        accept();
}

void DTUAddDialog::setup_ui()
{
    QGridLayout* layout = new QGridLayout();

    QLabel* name_l = new QLabel(QStringLiteral("名称"));
    name_l->setAlignment(Qt::AlignCenter);
    name_l->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    QLabel* pos_l = new QLabel(QStringLiteral("位置"));
    pos_l->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    pos_l->setAlignment(Qt::AlignCenter);
    name_ed = new QLineEdit();
    name_ed->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    pos_ed = new QLineEdit();
    pos_ed->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    okButton = new QPushButton(QStringLiteral("确认"));
    okButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    cancelButton = new QPushButton(QStringLiteral("取消"));
    cancelButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    layout->addWidget(name_l,0,0,1,2);
    layout->addWidget(name_ed,0,2,1,4);
    layout->addWidget(pos_l,1,0,1,2);
    layout->addWidget(pos_ed,1,2,1,4);
    layout->addWidget(okButton,2,0,1,3);
    layout->addWidget(cancelButton,2,3,1,3);

    setLayout(layout);
    setWindowTitle(QStringLiteral("新增DTU设备"));
    setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint | Qt::Drawer);
}
